# coding=utf-8
# author=haishan09@gmail.com
from __future__ import unicode_literals
from django.db import models
from measure.models import Measure


class Aggregate(models.Model):
    name = models.CharField('指标', max_length=64, unique=True)
    label = models.CharField('标签', max_length=64)
    measure = models.ForeignKey(Measure, blank=True, null=True)
    function = models.CharField(
        '函数', 
        max_length=64, 
        blank=True, 
        null=True,
        choices=[
            ('', '------'), 
            ('sum', 'sum'),
            ('count', 'count'),
            ('count_distinct', 'count_distinct'),
            ('min', 'min'),
            ('max', 'max'),
            ('avg', 'avg'),
        ]
    )
    expression = models.TextField('表达式', max_length=256, blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return self.label

